package server;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/1/21 21:40
 */
public class Response {

    private OutputStream out;

    public Response(OutputStream out) {
        this.out = out;
    }

    public void outputStringContent(String content) throws IOException {
        out.write(content.getBytes());
    }

    public void outputHtml(String url) {
        String absolutePath = StaticResourceUtil.getAbsolutePath(url);
        File file = new File(absolutePath);
        try {
            StaticResourceUtil.outputStaticSource(new FileInputStream(file), out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public OutputStream getOut() {
        return out;
    }

}
